import 'package:bubbles/ext/asset_ext.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:flutter/material.dart';

import '../../theme/color_palettes.dart';
import '../../utils/keep_alive_wrapper.dart';
import '../about/about_page.dart';
import '../home/home_page.dart';
import '../rank/rank_page.dart';
import '../rank/zone_page.dart';

class MainController extends GetxController with WidgetsBindingObserver {
  RxInt index = 0.obs;
  PageController pageController = PageController(initialPage: 0);

  final List<Widget> navPages = [
    const KeepAliveWrapper(child: HomePage()),
    const KeepAliveWrapper(child: RankPage()),
    //const KeepAliveWrapper(child: ZonePage(rid: 0,)),
    const KeepAliveWrapper(child: HomePage()),

    const KeepAliveWrapper(child: AboutPage()),
  ];

  RxList navigationBars = [].obs;

  final List<BottomNavigationBarItem> bottomNavigationBarItems = [
    _customBottomNavigationBarItem("nav_home".png, "nav_home_active".png, "主页"),
    _customBottomNavigationBarItem(
        "nav_home".png, "nav_home_active".png, "主页2"),
    _customBottomNavigationBarItem(
        "nav_home".png, "nav_home_active".png, "主页3"),
    _customBottomNavigationBarItem("nav_home".png, "nav_home_active".png, "关于"),
    // _customBottomNavigationBarItem(
    //     "nav_discovery".png, "nav_discovery_active".png, "发现"),
    // _customBottomNavigationBarItem(
    //     "nav_message".png, "nav_message_active".png, "消息"),
    // _customBottomNavigationBarItem("nav_my".png, "nav_my_active".png, "我的"),
  ];

  static BottomNavigationBarItem _customBottomNavigationBarItem(
      String defaultImage, String activeImage, String label) {
    return BottomNavigationBarItem(
        icon: Image.asset(defaultImage,
            width: 44.w,
            height: 44.w,
            color: ColorPalettes.instance.secondIcon),
        activeIcon: Obx(() {
          return RepaintBoundary(
            child: ColorFiltered(
                colorFilter: ColorFilter.mode(
                  ColorPalettes.instance.primary,
                  BlendMode.srcIn,
                ),
                child: Image.asset(activeImage,
                    width: 44.w,
                    height: 44.w,
                    color: ColorPalettes.instance.secondIcon)),
          );
        }),
        label: label);
  }

  void navigate(int index) {
    print("---$index");
    this.index.value = index;
    pageController.jumpToPage(index);
    //eventBus.fire(IndexNavigationIndexChangedEvent(index));
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    super.didChangeAppLifecycleState(state);
    //ventBus.fire(AppLifecycleStateEvent(state));
  }
}
